//
//  PictureSelectorViewController.swift
//  SinaWeiBo
//
//  Created by dengchen on 15/11/19.
//  Copyright © 2015年 name. All rights reserved.
//

import UIKit

private let reuseIdentifier = "Cell"
private let column:CGFloat = 4
private let pictureCellMaigin:CGFloat = 10.0
class PictureSelectorViewController: UICollectionViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    init() {
        let layout = UICollectionViewFlowLayout()
        let w = (DcScreenwidth - (column + 1) * pictureCellMaigin)/column
        layout.itemSize = CGSize(width: w, height: w)
        layout.minimumInteritemSpacing = pictureCellMaigin
        layout.minimumLineSpacing = pictureCellMaigin
        
        layout.sectionInset = UIEdgeInsets(top: pictureCellMaigin, left: pictureCellMaigin, bottom: 0, right: 0)
        super.init(collectionViewLayout: layout)
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI() {
        
        collectionView?.backgroundColor = UIColor.whiteColor()
        collectionView?.registerClass(pictureViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
    }
    
    
    //MARK:DataSoure
    
     override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 5
    }
    

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
      let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
       cell.backgroundColor = UIColor.blackColor()
        
        return cell
    }
  
}


class pictureViewCell: UICollectionViewCell {
    
    init() {
        super.init(frame: CGRectZero)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
       contentView.addSubview(addBtn)
       contentView.addSubview(deleteBtn)
        
        
        addBtn.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(contentView)
        }
        
        deleteBtn.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(contentView.snp_right)
            make.centerY.equalTo(contentView.snp_top)
        }
        
    }
    
    private let addBtn = UIButton(title: nil, bgImge: "compose_pic_add", titleColor: nil)
    
    private let deleteBtn = UIButton(title: nil, bgImge: "compose_photo_close", titleColor: nil)
    
}

